﻿//***********************************************************************************************
//* File Name	: EmailClientFactory.cs
//* Description	: This class is Factory class implementation. Contains factory methods for generating diffent type of email clients
//* 
//* Author		: Ashutosh Phoujdar(ashu.fouzdar@gmail.com)
//* Date		: 14-September-2014
//* ***********************************************************************************************

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace EmailFactory
{
    public class EmailClientFactory
    {
        static object lockObj = new object();
        //Singleton Object;
        static EmailClientFactory myObj = null;
        IEmailRepository imapRepostory = null;
        private EmailClientFactory() { }

        public static EmailClientFactory GetFactory()
        {
            lock (lockObj)
            {
                lock (lockObj)
                {
                    if (myObj == null)
                    {
                        myObj = new EmailClientFactory();
                    }
                }
                return myObj;
            }
        }

        public IEmailRepository GetImapRepository(string mailServer, int port, bool ssl, string login, string password)
        {
            if(imapRepostory == null)
            {
                imapRepostory = new ImapRepository(mailServer, port, ssl, login, password);
            }
            return imapRepostory;
        }
    }
}
